
var tangled_window_guid = 0;

function TangledWindow(grid, l, t, w, h) {
	this.img = 'tiles/64/'; // 'http://tangled-gadget.googlecode.com/svn/trunk/tiles/64/';
	this.p = new Array();
	this.grid = grid;
	this.p.l = l;
	this.p.t = t;
	this.p.w = w;
	this.p.h = h;
	this.guid = ++tangled_window_guid;

	this.init = function() {
	}

	this.draw = function() {
		var o = '';
		o = '<table border="0" cellpadding="0" cellspacing="0">';
		for (var r = 0; r < h; ++r) {
			o += '<tr>';
			for (var c = 0; c < w; ++c) {
				o += '<td><a href="javascript:void(null)" ';
				o += 'onClick="document.tangled_control.clicked_tile(' + this.guid + ', ' + r + ', ' + c + ')"';
				o += '><img src="';
				o += this.img;
				o += 'null-null-null.gif" name="';
				o += 'tangled_window_' + this.guid;
				o += '_' + r + '_' + c;
				o += '" border="0"/></a></td>';
			}
			o += '</tr>';
		}
		document.write(o);
	}

	this.trace_tile = function(r, c) {
		//alert("trace tile " + r + ":" + c);
		this.grid.trace_tile(r + this.p.t, c + this.p.l);
	}

	this.move = function(rows, cols) {
		this.p.t += rows;
		this.p.l += cols;
	}

	this.update = function() {
		for (var r = 0; r < h; ++r) {
			for (var c = 0; c < w; ++c) {
				document.images[
					'tangled_window_' + this.guid +
					'_' + r + '_' + c
				].src = this.img + 
					this.grid.tile_key(
						r + this.p.t, c + this.p.l
					) + '.gif';
			}
		}
	}

	this.init();
}
